import axiosInstance from "../../plugins/axios";
import { ElMessage } from "element-plus";

export const generateReport = async (projectId:any) => {
  const res = await axiosInstance.post(
    `/costReport/reportReceive?id=${projectId}`
  );
  if (res.data.code == 1) {
	  ElMessage.success("生成报告成功");
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "生成报告失败");
    throw new Error(res.data.message || "生成报告失败");
  }
};

export const updateProcessHistory = async (data:any) => {
  const res = await axiosInstance.post(
    `/tasks/updateProgress`,data
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const getProcess = async (id:string) => {
  const res = await axiosInstance.post(
    `/workloadProcess/get?id=${id}`,
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const getBenchmark = async () => {
  const res = await axiosInstance.get(
    `/cost/benchmark`
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const getQR = async (id: string) => {
  const res = await axiosInstance.get(
    `/swf/QR?id=${id}`
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const getCostInfo = async (id: string) => {
  const res = await axiosInstance.post(
    `/cost/get?id=${id}`
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const getWorkload = async (s:any,pdr:any,swf:any,rdf:any) => {
  const res = await axiosInstance.post(
    `/cost/workload?s=${s}&pdr=${pdr}&swf=${swf}&rdf=${rdf}`
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "PDR信息不存在");
    throw new Error(res.data.message || "PDR信息不存在");
  }
};

export const updateCostInfo = async (formData: any) => {
  const res = await axiosInstance.post(
    `/cost/update`,formData
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "更新失败");
    throw new Error(res.data.message || "更新失败");
  }
};

export const uploadFile = async (file: any) => {
  const res = await axiosInstance.post(
    `/minio/upload`,file
  );
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "更新失败");
    throw new Error(res.data.message || "更新失败");
  }
};


